import { HookController } from "./HookController";
import { FishingGlobal } from "../FishingGlobal";
import { Hook } from "../Obj/Hook";
import { HookState } from "../defin/HookState";
//class HookAutoSwingController
    
    export  class HookAutoSwingController extends HookController
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ addListeners(): void
        {
            FishingGlobal.scene.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        protected /* override */ removeListeners(): void
        {
            FishingGlobal.scene.removeEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        public /* override */ autoRun(): void
        {
            var loc2=NaN;
            super.autoRun();
            var loc1=_target as Hook;
            if (loc1.hookState == HookState.swing) 
            {
                loc2 = loc1.angle;
                if (this._isAdd) 
                {
                    loc2 = loc2 + this.Speed;
                    if (loc2 >= this.MaxAngle) 
                    {
                        loc2 = this.MaxAngle;
                        this._isAdd = !this._isAdd;
                    }
                }
                else 
                {
                    loc2 = loc2 - this.Speed;
                    if (loc2 <= this.MinAngle) 
                    {
                        loc2 = this.MinAngle;
                        this._isAdd = !this._isAdd;
                    }
                }
                loc1.angle = loc2;
            }
            return;
        }

        /* internal  */onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=_target as Hook;
            super.startHook();
            return;
        }

        /* internal */ /* const */MaxAngle: number=60;

        /* internal */ /* const */MinAngle: number=-60;

        /* internal */ /* const */Speed: number=1.5;

        /* internal */ /* var */_isAdd: Boolean=true;
    }
